package net.roobook.common.configure;

import net.roobook.common.handler.RoobookAccessDeniedHandler;
import net.roobook.common.handler.RoobookAuthExceptionEntryPoint;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.security.web.access.AccessDeniedHandler;

/**
 * @Author cos
 * @description 配置类，注册accessDeniedHandler，authenticationEntryPoint 使用@Enable模块驱动的方式,注册到各个微服务子系统的Spring IOC容器中
 * @date 2022/4/8
 */
public class RoobookAuthExceptionConfigure {
    // @ConditionalOnMissingBean(name = "accessDeniedHandler")为例，当微服务系统的Spring IOC容器中没有名称为accessDeniedHandler的Bean的时候，
    // 就将RoobookAccessDeniedHandler注册为一个Bean。这样做的好处在于，子系统可以自定义自个儿的资源服务器异常处理器，覆盖我们在common通用模块里定义的
    @Bean
    @ConditionalOnMissingBean(name = "accessDeniedHandler")
    public RoobookAccessDeniedHandler accessDeniedHandler() {
        return new RoobookAccessDeniedHandler();
    }

    @Bean
    @ConditionalOnMissingBean(name = "authenticationEntryPoint")
    public RoobookAuthExceptionEntryPoint authenticationEntryPoint() {
        return new RoobookAuthExceptionEntryPoint();
    }
}
